﻿package view.component
{
    import __AS3__.vec.*;
    import com.core.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.sh.game.global.*;
    import com.sh.game.util.*;
    import control.*;
    import flash.display.*;
    import morn.core.components.*;

    public class LianZhan extends Sprite
    {
        private var _numsContainer:Sprite;
        private var _curNum:int = 0;
        private var _bitmaps:Vector.<Image>;
        private var _bg:Image;
        private var _tween:TweenLite;
        private var _hideTween:TweenMax;
        private var _timeout:int;
        private var _parent:DisplayObjectContainer;
        private var _tweenMax:TweenMax;
        private var _count:int = 0;
        private var _mapState:int = 0;

        public function LianZhan(param1:DisplayObjectContainer)
        {
            this._parent = param1;
            this.init();
            return;
        }// end function

        private function init() : void
        {
            this._numsContainer = new Sprite();
            this._bg = new Image();
            this._bg.url = Config.getUrl("assets/images/lianzhan/lianzhan.png");
            this.addChild(this._bg);
            this.addChild(this._numsContainer);
            this._numsContainer.x = 30;
            this._numsContainer.y = 67;
            this.x = 30;
            this.y = 250;
            var _loc_1:* = Control.create(LianZhanControl, this);
            ModelProxy.addObserver("lianzhan", _loc_1);
            return;
        }// end function

        public function addNumber(param1:String, param2:Sprite, param3:int, param4:int) : Vector.<Image>
        {
            var _loc_14:Image = null;
            var _loc_15:String = null;
            var _loc_16:Image = null;
            var _loc_5:* = param1.length;
            var _loc_6:int = 0;
            var _loc_7:* = param3;
            var _loc_8:int = 37;
            var _loc_9:int = 47;
            var _loc_10:int = 0;
            var _loc_11:* = new Vector.<Image>;
            var _loc_12:int = 0;
            while (_loc_12 < _loc_5)
            {
                
                _loc_15 = param1.charAt(_loc_12);
                _loc_16 = new Image();
                _loc_16.url = Config.getUrl("assets/images/lianzhan/" + _loc_15 + ".png");
                param2.addChild(_loc_16);
                _loc_6 = _loc_6 + (_loc_8 - 8);
                _loc_11.push(_loc_16);
                _loc_12++;
            }
            var _loc_13:* = (-_loc_6) / 2;
            _loc_6 = 0;
            for each (_loc_14 in _loc_11)
            {
                
                _loc_14.x = _loc_7 + _loc_6 + _loc_13;
                _loc_14.y = param4 - _loc_9 / 2;
                _loc_6 = _loc_6 + (_loc_8 - 8);
            }
            return _loc_11;
        }// end function

        public function add(param1:int = 1) : void
        {
            var _loc_3:Image = null;
            var _loc_2:* = ConfigDictionary.data.maplist[UserData.getUserData("mapid")];
            if (_loc_2)
            {
                this._mapState = _loc_2.lianzhan;
            }
            this._parent.addChild(this);
            this._curNum = this._curNum + param1;
            if (this._curNum > 999)
            {
                this._curNum = 999;
            }
            if (this._bitmaps && this._bitmaps.length > 0)
            {
                for each (_loc_3 in this._bitmaps)
                {
                    
                    if (_loc_3.parent)
                    {
                        _loc_3.parent.removeChild(_loc_3);
                    }
                }
                this._bitmaps = null;
            }
            this._bitmaps = this.addNumber(this._curNum + "", this._numsContainer, 0, 0);
            if (this._tween)
            {
                this._tween.kill();
            }
            if (this._hideTween)
            {
                this._hideTween.kill();
                this._hideTween = null;
                this.alpha = 1;
            }
            this._numsContainer.scaleX = 4;
            this._numsContainer.scaleY = 4;
            this._numsContainer.alpha = 0.8;
            if (this._bitmaps.length >= 3)
            {
                this._bg.x = 16;
            }
            else
            {
                this._bg.x = 0;
            }
            this._tween = TweenLite.to(this._numsContainer, 0.5, {scaleX:1, scaleY:1, alpha:1, ease:Elastic.easeOut, onComplete:this.onComplete});
            this._bg.scaleX = 1;
            this._bg.scaleY = 1;
            if (this._tweenMax)
            {
                this._tweenMax.kill();
            }
            this._tweenMax = TweenMax.to(this._bg, 0.1, {scaleX:0.97, scaleY:0.97, yoyo:true, repeat:1, ease:Elastic.easeOut, delay:0.1, onComplete:this.onComplete2});
            if (this._mapState != 2)
            {
                if (this._timeout > 0)
                {
                    SecondTimerUtil.instance.removeTask(this._timeout);
                    this._timeout = 0;
                }
                this._count = 0;
                this._timeout = SecondTimerUtil.instance.addSecondTask(this.hideRender);
            }
            return;
        }// end function

        private function hideRender() : void
        {
            var _loc_1:String = this;
            var _loc_2:* = this._count + 1;
            _loc_1._count = _loc_2;
            if (this._count == 10)
            {
                this.close();
            }
            else if (this._count > 6)
            {
                if (this._hideTween)
                {
                    this._hideTween.kill();
                }
                this.alpha = 1;
                this._hideTween = TweenMax.to(this, 0.4, {alpha:0.2, yoyo:true, repeat:1, onComplete:this.onHideTweenComp});
            }
            return;
        }// end function

        public function close() : void
        {
            if (this.parent)
            {
                this.parent.removeChild(this);
            }
            this._curNum = 0;
            SecondTimerUtil.instance.removeTask(this._timeout);
            this._timeout = 0;
            return;
        }// end function

        private function onHideTweenComp() : void
        {
            this._hideTween = null;
            return;
        }// end function

        private function onComplete2() : void
        {
            this._tweenMax = null;
            this._bg.scaleX = 1;
            this._bg.scaleY = 1;
            return;
        }// end function

        private function onComplete() : void
        {
            this._numsContainer.scaleX = 1;
            this._numsContainer.scaleY = 1;
            this._numsContainer.alpha = 1;
            this._tween = null;
            return;
        }// end function

    }
}
